"""
    >>> self = (3.0, 4.0)
    >>> go = __format__(self, ".3fp")
    >>> go
    '<5.000, 0.927>'
"""

import math as m


def abs(*args):
    return m.hypot(*args)


def angle(self):
    return m.atan2(*reversed(self))


def __format__(self, fmt_spec=""):
    def inner_fmt(it, fmt):
        return (format(x, fmt) for x in it)

    if fmt_spec.endswith("p"):
        fmt_spec = fmt_spec[:-1]
        ret = (abs(*self), angle(self))
        # print(inner_fmt(ret, fmt_spec))
        return "<{}, {}>".format(*inner_fmt(ret, fmt_spec))
    else:
        # print(inner_fmt(self, fmt_spec))
        return "({}, {})".format(*inner_fmt(self, fmt_spec))


self = (3.0, 4.0)
go = __format__(self, ".3fp")

if __name__ == "__main__":
    import doctest

    print("format-basic.py测试开始")
    (ff, tt) = doctest.testmod()
    print("测试结束:统计-失败{},总计{}".format(ff, tt))
    print("√" * tt if tt > 0 and not ff else "无测试" if not ff else "×" * ff)
